import pygame, sys
from pygame.locals import *

# set up pygame
pygame.init()
mainClock = pygame.time.Clock()

S_WIDTH = 640
S_HEIGHT = 480

# set up the window
windowSurface = pygame.display.set_mode((S_WIDTH, S_HEIGHT), 0, 32)
pygame.display.set_caption('ch2_6')

BLACK = (0, 0, 0)

bg = pygame.Rect(0, 0, S_WIDTH, S_HEIGHT)
bgImage = pygame.image.load('bg.bmp')

DRAGON_W = 95
DRAGON_H = 99

dragonRect = pygame.Rect(560, 350, DRAGON_W, DRAGON_H)
dragon = pygame.image.load('dra.bmp')
dragon.set_colorkey(BLACK)
cur = 0

while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            sys.exit()

    windowSurface.blit(bgImage, bg)
    rect = dragonRect.move(-cur * 10, 0)
    windowSurface.blit(dragon, rect, ((cur % 8) * DRAGON_W, 0, DRAGON_W, DRAGON_H))
    cur = (cur+1, 0)[cur == 64]
    pygame.display.update()
    mainClock.tick(10)
